package com.superman.supermarket.client.place;

import com.google.gwt.inject.client.AsyncProvider;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.superman.mvpframe.client.mvp.ActivityAbstractPlace;
import com.superman.mvpframe.client.mvp.ActivityAsyncCallBackHandler;
import com.superman.mvpframe.client.router.INeedLoginPlace;
import com.superman.supermarket.client.activity.OrderListActivity;

/**
 * 订单列表路由
 * 
 * @author superman
 * @version 2018年7月18日下午3:11:58
 */
public class OrderListPlace extends ActivityAbstractPlace<OrderListActivity> implements INeedLoginPlace{

	@Prefix("orderlist")
	public static class Tokenizer implements PlaceTokenizer<OrderListPlace> {

		private final Provider<OrderListPlace> placeProvider;

		@Inject
		public Tokenizer(Provider<OrderListPlace> placeProvider) {
			this.placeProvider = placeProvider;
		}

		@Override
		public OrderListPlace getPlace(String token) {
			OrderListPlace place = placeProvider.get();
			return place;
		}

		@Override
		public String getToken(OrderListPlace place) {
			return System.currentTimeMillis() + "";
		}

	}

	@Inject
	AsyncProvider<OrderListActivity> af;

	@Override
	public void getActivity(final ActivityAsyncCallBackHandler activityCallbackHandler) {
		af.get(new AsyncCallback<OrderListActivity>() {

			@Override
			public void onFailure(Throwable caught) {

			}

			@Override
			public void onSuccess(OrderListActivity result) {
				activityCallbackHandler.onReceive(result);
				onActivityCreated(result);
			}
		});
	}
}
